/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package view.panels.importDSpanel;

import java.io.IOException;
import java.util.List;
import javax.swing.DefaultListModel;
import javax.swing.JOptionPane;
import model.dataset.Dsmetaattribute;
import view.controllers.ControllerUI_Main;
import view.controllers.ControllerUI_MetaAttributes;

/**
 *
 * @author Jelena
 */
public class PaneAnylNewMetaAttribute extends javax.swing.JPanel {

    /**
     * Creates new form PaneAnylNewMetaAttribute
     */
    public PaneAnylNewMetaAttribute() {
        initComponents();
        fillList();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        btnCalculate = new javax.swing.JButton();
        bnNoCalculate = new javax.swing.JButton();

        jScrollPane1.setViewportView(jList1);

        jLabel1.setText("Metaattributes that should be calculated:");

        jLabel2.setText("Would you like to calculate it?");

        btnCalculate.setText("Calculate");
        btnCalculate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCalculateActionPerformed(evt);
            }
        });

        bnNoCalculate.setText("No");
        bnNoCalculate.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bnNoCalculateActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 380, Short.MAX_VALUE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE))
                    .addComponent(jLabel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGap(0, 0, Short.MAX_VALUE)
                        .addComponent(bnNoCalculate, javax.swing.GroupLayout.PREFERRED_SIZE, 63, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCalculate)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 199, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnCalculate)
                    .addComponent(bnNoCalculate))
                .addContainerGap())
        );
    }// </editor-fold>//GEN-END:initComponents

    private void bnNoCalculateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bnNoCalculateActionPerformed
        ControllerUI_Main.getInstance().setActivePanel(new PanelWelcome());
    }//GEN-LAST:event_bnNoCalculateActionPerformed

    private void btnCalculateActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCalculateActionPerformed
        try {
            ControllerUI_MetaAttributes.getInstance().recalculateMetaAttributes();
            JOptionPane.showMessageDialog(this, "Metaattributes are succesfully recalculated.");
            ControllerUI_Main.getInstance().setActivePanel(new PanelWelcome());
        } catch (IOException ex) {
            JOptionPane.showMessageDialog(this, "Metaattributes have not been recalculated.", "", JOptionPane.ERROR_MESSAGE);
        }
    }//GEN-LAST:event_btnCalculateActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton bnNoCalculate;
    private javax.swing.JButton btnCalculate;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    // End of variables declaration//GEN-END:variables

    private void fillList(){
        List<Dsmetaattribute> calculatedMetaAttribute = ControllerUI_MetaAttributes.getInstance().getUnCalculatedMetaAttribute();
        if(!calculatedMetaAttribute.isEmpty()){
        DefaultListModel dlm = new DefaultListModel();
            for (Dsmetaattribute dsma : calculatedMetaAttribute) {
                dlm.addElement(dsma);
            }
            jList1.setModel(dlm);
            System.out.println("Seted list");
        }else{
            JOptionPane.showMessageDialog(this, "There are no uncalculated metaattributes.");
        }
    }

}
